<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            width: 500px;
            height: 200px;
            border: 1px solid #ccc;
            margin: 50px auto;
            overflow: hidden;
        }

        ul {
            width: 600px;
            height: 40px;

            margin-left: -1px;
            list-style: none;
        }

        li {
            float: left;
            width: 101px;
            height: 40px;
            text-align: center;
            font: 600 18px/40px 'simsun';
            background-color: pink;
            cursor: pointer;
        }

        span {
            display: none;
            width: 500px;
            height: 460px;
            background-color: yellow;
            text-align: center;
            font: 700 100px/160px 'simsun';
        }

        .show {
            display: block;
        }

        .current {
            background-color: yellow;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li class="current">鞋子</li>
            <li>袜子</li>
            <li>帽子</li>
            <li>裤子</li>
            <li>裙子</li>
        </ul>
        <span class="show">鞋子</span>
        <span>袜子</span>
        <span>帽子</span>
        <span>裤子</span>
        <span>裙子</span>
    </div>


    <script>
        let liArrs = document.getElementsByTagName('li')
        let spanArrs = document.getElementsByTagName('span')
        console.log(liArrs, spanArrs);

        for (let i = 0; i < liArrs.length; i++) {


            liArrs[i].index=i  //把索引绑定给数值 后面spanArrs会用到
            liArrs[i].onmouseover = function () {

                //清除掉所有类名之后再给this添加类名
                for (let j = 0; j < liArrs.length; j++) {
                    liArrs[j].className = ''
                    spanArrs[j].className = ''
                }
                this.className = 'current'
                spanArrs[this.index].className = 'show'
            }

        }

    </script>
</body>

</html>